/*******************************************************************************
 *                           TacticaHimura.java                                *
 *                           Cesar Himura Elric                                *
 *                              JavaCup 2009                                   *
 *******************************************************************************/

package org.javahispano.javacup.tacticas_aceptadas.Himura;

import org.javahispano.javacup.modelo.Posicion;

public class Balon
{
    private double x,  y;
    private double altura = 0.0;

    public Balon(double x, double y)
    {
        this.x = x;
        this.y = y;
    }

    public Balon(Posicion p)
    {
        x = p.getX();
        y = p.getY();
    }

    public double getX()
    {
        return x;
    }

    public double getY()
    {
        return y;
    }

    public void setAltura(double altura)
    {
        this.altura = altura;
    }

    public double getAltura()
    {
        return altura;
    }

    public double angulo(Balon p) {
        double angle = 0;
        double dx = p.getX() - x;
        double dy = p.getY() - y;
        if (dx > 0) {
            angle = Math.atan(dy / dx);
        } else if (dx < 0) {
            angle = Math.atan(dy / dx) + Math.PI;
        } else if (dy < 0) {
            angle = -Math.PI / 2;
        } else {
            angle = Math.PI / 2;
        }

        angle = angle % (Math.PI * 2d);
        if (angle >= Math.PI) {
            angle = angle - 2d * Math.PI;
        }
        return angle;
    }

    public double angulo(Posicion p) {
        double angle = 0;
        double dx = p.getX() - x;
        double dy = p.getY() - y;
        if (dx > 0) {
            angle = Math.atan(dy / dx);
        } else if (dx < 0) {
            angle = Math.atan(dy / dx) + Math.PI;
        } else if (dy < 0) {
            angle = -Math.PI / 2;
        } else {
            angle = Math.PI / 2;
        }

        angle = angle % (Math.PI * 2d);
        if (angle >= Math.PI) {
            angle = angle - 2d * Math.PI;
        }
        return angle;
    }

    public double distancia(Posicion p) {
        return Math.sqrt((x - p.getX()) * (x - p.getX()) + (y - p.getY()) * (y - p.getY()));
    }
}